package com.qf.ssm.controller;

import com.qf.ssm.dto.R;
import com.qf.ssm.pojo.Humiture;
import com.qf.ssm.service.HumituryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/humitures")
public class HumituryController {

    private HumituryService humituryService;

    @Autowired
    public void setHumituryService(HumituryService humituryService) {
        this.humituryService = humituryService;
    }

    @GetMapping("/humitures")
    public R getAllData(){
        List<Humiture> humitureList = humituryService.findAll();
        List<Double> temperatureList = humitureList.stream().map(Humiture::getTemperature).collect(Collectors.toList());
        List<Double> humidityList = humitureList.stream().map(Humiture::getHumidity).collect(Collectors.toList());
        List<Date> timeList = humitureList.stream().map(Humiture::getUploaddate).collect(Collectors.toList());
        System.err.println(timeList);
        System.err.println(temperatureList);
        System.err.println(humidityList);
        HashMap<Object,Object>map=new HashMap<>();
        map.put("times",timeList);
        map.put("temperatureList",temperatureList);
        map.put("humidityList",humidityList);
        return R.setOK(map);
    }
}
